package com.vinjune.distributed.redislock;

import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by 000376 on 2017/12/7.
 */
public class LockSupport {

    static ConcurrentHashMap<String, RedisDisLock> lockMap = new ConcurrentHashMap<String, RedisDisLock>();

    public static DisLock getRedisLock(String lockKey) {
        RedisDisLock lock = null;
        if (lockMap.contains(lockKey)) {
            lock = lockMap.get(lockKey);
        } else {
            RedisDisLock lockN = new RedisDisLock(lockKey);
            lock = lockMap.putIfAbsent(lockKey, lockN);
            if (lock == null) {
                lock = lockN;
            }
        }
        return lock;
    }
}
